import json from "@rollup/plugin-json";
import typescript from "@rollup/plugin-typescript";
import copy from "rollup-plugin-copy";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";

/**
 * @type {import('rollup').RollupOptions}
 */
export default {
  input: "./index.ts",
  output: {
    file: "./dist/index.js",
    format: "esm",
  },
  plugins: [
    commonjs({
      include: /node_modules/,
      esmExternals: true,
    }),
    json(),
    typescript({
      tsconfig: "./tsconfig.json",
    }),
    copy({
      targets: [
        {
          src: "template/*",
          dest: "dist/template",
          ignore: ["node_modules", "dist"],
        },
        { src: "locale/*", dest: "dist/locale" },
      ],
    }),
    nodeResolve({
      extensions: [".ts", ".js", ".json"], // 添加需要解析的扩展名
      alias: {
        "@": "./",
      },
    }),
  ],
  external: ["commander", "fs-extra", "path", "url", "chalk", "ejs"],
};
